package com.wizinno.android.urineflow.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.wizinno.android.urineflow.R;
import com.wizinno.android.urineflow.application.ExitApplication;
import com.wizinno.android.urineflow.constant.ActionConstant;
import com.wizinno.android.urineflow.constant.CommonControl;
import com.wizinno.android.urineflow.fragment.DistanceFragment;
import com.wizinno.android.urineflow.fragment.SteeringFragment;
import com.wizinno.android.urineflow.fragment.SystemFragment;
import com.wizinno.android.urineflow.fragment.WeightFragment;

public class SettingBaseActivity extends BaseActivity {

    private static SystemFragment systemFragment;
    private static SteeringFragment steeringFragment;
    private static DistanceFragment distanceFragment;
    private static WeightFragment weightFragment;

    private TextView tv_setting_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ExitApplication.getInstance().addActivity(this);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_base);
        tv_setting_title = findViewById(R.id.tv_setting_title);
        setFragment();
        CommonControl.INSTANCE.settingBaseActivity = this;
    }

    private void setFragment() {
        Intent intent = getIntent();
        String action = intent.getAction();
        switch (action) {
            case ActionConstant.SYSTEM:
                tv_setting_title.setText("系统设置");
                systemFragment = new SystemFragment();
                switchFragment(null, systemFragment, R.id.fl_setting);
                break;
            case ActionConstant.STEERING:
                tv_setting_title.setText("阀门&电机");
                steeringFragment = new SteeringFragment();
                switchFragment(null, steeringFragment, R.id.fl_setting);
                break;
            case ActionConstant.DISTANCE:
                tv_setting_title.setText("距离传感器");
                distanceFragment = new DistanceFragment();
                switchFragment(null, distanceFragment, R.id.fl_setting);
                break;
            case ActionConstant.WEIGHT:
                tv_setting_title.setText("称重传感器");
                weightFragment = new WeightFragment();
                switchFragment(null, weightFragment, R.id.fl_setting);
                break;
        }
    }

    public static void setValveStatus(byte[] receiveBytes) {
        steeringFragment.setValveStatus(receiveBytes);
    }

    public static void setWeight(byte[] receiveBytes) {
        if (weightFragment != null) {
            weightFragment.setWeight(receiveBytes);
        }
    }

    public static void setAdc(byte[] receiveBytes) {
        if (weightFragment != null) {
            weightFragment.setAdc(receiveBytes);
        }
    }

    public static void setCheck0(byte[] receiveBytes) {
        if (weightFragment != null) {
            weightFragment.setCheck0(receiveBytes);
        }
    }

    public static void setCheck500(byte[] receiveBytes) {
        if (weightFragment != null) {
            weightFragment.setCheck500(receiveBytes);
        }
    }

    public static void setDistancePeople(byte[] receiveBytes) {
        if (distanceFragment != null) {
            distanceFragment.setDistancePeople(receiveBytes);
        }
    }

    public static void setDistancePeopleTime(byte[] receiveBytes) {
        if (distanceFragment != null) {
            distanceFragment.setDistancePeopleTime(receiveBytes);
        }
    }

    public static void setDistanceButton(byte[] receiveBytes) {
        if (distanceFragment != null) {
            distanceFragment.setDistanceButton(receiveBytes);
        }
    }

    public static void setDistanceButtonTime(byte[] receiveBytes) {
        if (distanceFragment != null) {
            distanceFragment.setDistanceButtonTime(receiveBytes);
        }
    }

    public static void setDistance(byte[] receiveBytes) {
        if (distanceFragment != null) {
            distanceFragment.setDistance(receiveBytes);
        }
    }

    public static void setDistanceEvent(byte event) {
        if (distanceFragment != null) {
            distanceFragment.setDistanceEvent(event);
        }
    }

    public static void setSteeringStatus(byte[] receiveBytes) {
        if (steeringFragment != null) {
            steeringFragment.setSteeringStatus(receiveBytes);
        }
    }

    public static void setSteeringCurrent(byte[] receiveBytes) {
        if (steeringFragment != null) {
            steeringFragment.setSteeringCurrent(receiveBytes);
        }
    }

    public void toSystemSetting(View view) {
        DistanceFragment.startDistance(true);
        Intent intent = new Intent(SettingBaseActivity.this, SystemSettingActivity.class);
        startActivity(intent);
    }
}